home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / Asm / Demos / BouncingBobs.s < prev    next >
Encoding:
Text File  |  1997-12-16  |  9.6 KB  |  419 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      Bouncing Bobs
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5. ;
  6. ;This is a demonstration of bouncing bobs, an extension of the original
  7. ;Raining BOBs demo.  It runs in high-resolution + lace with a total of 35
  8. ;16x16 bobs at 50 FPS ('020+FAST).
  9.  
  10.     INCDIR    "INCLUDES:"
  11.     INCLUDE    "dpkernel/dpkernel.i"
  12.  
  13. MAX_IMAGES =    35
  14.  
  15.     SECTION    "Demo",CODE
  16.  
  17. ;===========================================================================;
  18. ;                             INITIALISE DEMO
  19. ;===========================================================================;
  20.  
  21.     STARTDPK
  22.  
  23. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  24.     move.l    DPKBase(pc),a6    ;Load bob picture.
  25.     lea    PIC_BobTags(pc),a0
  26.     CALL    Init
  27.     tst.l    d0
  28.     beq.s    .Exit
  29.  
  30.     move.l    PIC_Bobs(pc),a1
  31.     move.l    a1,BallPic
  32.     move.l    a1,LacedPic
  33.  
  34.     move.l    PIC_Palette(a1),GSPalette
  35.     move.l    PIC_Bitmap(a1),a2
  36.     move.l    BMP_AmtColours(a2),GSColours
  37.  
  38.     moveq    #ID_RASTER,d0    ;Get raster object.
  39.     CALL    Get
  40.     move.l    d0,Raster
  41.     beq.s    .Exit
  42.  
  43.     move.l    Raster(pc),a0    ;a0 = Raster
  44.     lea    RastCList(pc),a1    ;a1 = Colourlist
  45.     move.l    a1,RAS_Command(a0)    ;a0 = Raster->Command = Colourlist;
  46.     move.l    a0,RSH_Prev(a1)    ;a1 = Colourlist->Prev = Raster;
  47.  
  48.     lea    ScreenTags(pc),a0    ;Initialise screen.
  49.     sub.l    a1,a1
  50.     CALL    Init
  51.     tst.l    d0
  52.     beq.s    .Exit
  53.  
  54. ;--------------------------------------------------------------------------;
  55. ;Initialise restore and bob objects.
  56.  
  57.     lea    RestoreTags(pc),a0
  58.     move.l    Screen(pc),a1    ;a1 = Screen.
  59.     CALL    Init    ;>> = Initialise the restore list.
  60.     tst.l    d0    ;d0 = Check for errors.
  61.     beq.s    .Exit    ;>> = Error, exit.
  62.  
  63.     lea    TAGS_Ball(pc),a0    ;Initialise the Ball mbob.
  64.     move.l    Screen(pc),a1
  65.     CALL    Init
  66.     tst.l    d0
  67.     beq.s    .Exit
  68.  
  69.     lea    TAGS_Interlaced(pc),a0    ;Initialise "HiRes Interlaced" bob.
  70.     move.l    Screen(pc),a1
  71.     CALL    Init
  72.     tst.l    d0
  73.     beq.s    .Exit
  74.  
  75.     moveq    #ID_JOYDATA,d0    ;Get joydata structure for reading
  76.     CALL    Get    ;port 0.
  77.     move.l    d0,JoyData
  78.     beq.s    .Exit
  79.     move.l    d0,a0    ;Initialise the joydata structure.
  80.     sub.l    a1,a1
  81.     CALL    Init
  82.     tst.l    d0
  83.     beq.s    .Exit
  84.  
  85.     move.l    Screen(pc),a0
  86.     CALL    Display
  87.  
  88.     bsr.s    Main
  89.  
  90. .Exit    move.l    DPKBase(pc),a6
  91.     move.l    JoyData(pc),a0
  92.     CALL    Free
  93.     move.l    BOB_Interlaced(pc),a0
  94.     CALL    Free
  95.     move.l    MBOB_Ball(pc),a0
  96.     CALL    Free
  97.     move.l    Restore(pc),a0
  98.     CALL    Free
  99.     move.l    Screen(pc),a0
  100.     CALL    Free
  101.     move.l    PIC_Bobs(pc),a0
  102.     CALL    Free
  103.     move.l    Raster(pc),a0
  104.     CALL    Free
  105.     MOVEM.L    (SP)+,A0-A6/D1-D7
  106.     moveq    #ERR_OK,d0
  107.     rts
  108.  
  109. ;===========================================================================;
  110. ;                                DEMO CODE
  111. ;===========================================================================;
  112.  
  113. Main:    move.l    Screen(pc),a2    ;a2 = Screen.
  114.     move.l    GS_Bitmap(a2),a3    ;a3 = Bitmap.
  115.  
  116.     move.l    BOB_Interlaced(pc),a1    ;a1 = Bob to draw.
  117.     move.w    GS_Width(a2),d0
  118.     sub.w    BOB_Width(a1),d0
  119.     move.w    d0,BOB_XCoord(a1)
  120.     clr.w    BOB_YCoord(a1)
  121.  
  122.     move.l    DPKBase(pc),a6    ;a6 = DPKBase.
  123.     move.l    GS_MemPtr2(a2),BMP_Data(a3)
  124.     move.l    BOB_Interlaced(pc),a0    ;a0 = Bob to draw.
  125.     CALL    Draw    ;>> = Draw the Bob
  126.  
  127.     move.l    GS_MemPtr1(a2),BMP_Data(a3)
  128.     move.l    BOB_Interlaced(pc),a0    ;a0 = Bob to draw.
  129.     CALL    Draw    ;>> = Draw the Bob
  130.  
  131.     moveq    #$00,d7
  132.     move.l    MBOB_Ball(pc),a1
  133.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  134.     move.w    MB_AmtEntries(a1),d2    ;a2 = Amount of entries.
  135.     subq.w    #1,d2    ;d2 = --1 for loop.
  136.     moveq    #$00,d3
  137.  
  138. .create    eor.w    #1,d3
  139.     moveq    #8,d1    ;Set Y speed here.
  140.     CALL    FastRandom
  141.     addq.w    #2,d0
  142.     move.w    d0,BE_YSpeed(a2)
  143.     move.w    #8,d1    ;Set X speed here.
  144.     CALL    FastRandom
  145.     addq.w    #1,d0
  146.     move.w    d0,BE_XSpeed(a2)
  147.     tst.w    d3
  148.     beq.s    .posx
  149.     neg.w    BE_XSpeed(a2)
  150.  
  151. .posx    move.l    Screen(pc),a0
  152.     move.w    GS_Height(a0),d1    ;Starting Y coordinate.
  153.     asr.w    #1,d1
  154.     CALL    FastRandom
  155.     asr.w    #1,d1
  156.     add.w    d1,d0
  157.     move.w    d0,BE_YCoord(a2)
  158.  
  159.     move.w    GS_Width(a0),d1    ;Starting X coordinate.
  160.     CALL    FastRandom
  161.     move.w    d0,BE_XCoord(a2)
  162.  
  163.     moveq    #12,d1
  164.     CALL    FastRandom
  165.     move.w    d0,BE_Frame(a2)
  166.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  167.     move.w    #1,BE_FChange(a2)
  168.     move.w    d3,BE_Locked(a2)
  169.  
  170.     lea    NBE_SIZEOF(a2),a2
  171.     dbra    d2,.create
  172.     bra.s    Loop
  173.  
  174. .Sets    dc.b    0,0,0,0
  175.     dc.b    1,1,1,1
  176.     dc.b    2,2,2,2
  177.  
  178. ;---------------------------------------------------------------------------;
  179.  
  180. Loop:    move.l    Screen(pc),a0    ;a0 = Screen.
  181.     move.l    MBOB_Ball(pc),a1
  182.     addq.w    #1,d7
  183.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  184.     move.w    MB_AmtEntries(a1),d2
  185.     subq.w    #1,d2
  186. .update    bsr.s    UpdateBob
  187.     lea    NBE_SIZEOF(a2),a2
  188.     dbra    d2,.update
  189.  
  190.     move.l    DPKBase(pc),a6
  191.     move.l    Restore(pc),a0
  192.     CALL    Activate
  193.  
  194.     move.l    MBOB_Ball(pc),a0    ;a0 = Bob to draw.
  195.     CALL    Draw    ;>> = Draw the Bob.
  196.  
  197.     move.l    SCRBase(pc),a6
  198.     CALL    scrWaitAVBL
  199.  
  200.     move.l    Screen(pc),a0
  201.     CALL    scrSwapBuffers
  202.  
  203.     move.l    DPKBase(pc),a6
  204.     move.l    JoyData(pc),a0
  205.     CALL    Query
  206.     move.l    JoyData(pc),a0
  207.     move.l    JD_Buttons(a0),d0
  208.     btst    #JB_LMB,d0
  209.     beq.s    Loop
  210.     rts
  211.  
  212. ;===========================================================================;
  213. ;                               UPDATE A BOB
  214. ;===========================================================================;
  215. ;Function: Moves the entity according to its internal settings.
  216. ;Requires: a1 = Bob structure.
  217. ;       a2 = Entry to update.
  218.  
  219. GRAVITY =    1
  220.  
  221. UpdateBob:
  222.     move.l    MB_Screen(a1),a0    ;a0 = Bitmap
  223.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  224.     add.w    BE_YSpeed(a2),d0    ;d0 = (YCoord)+YSpeed
  225.     cmp.w    GS_Height(a0),d0    ;d0 = Should this bob bounce?
  226.     blt.s    .NoBounce    ;>> = No.
  227.     neg.w    BE_YSpeed(a2)    ;a2 = Bounce the bob!
  228.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the bob down.
  229.     bra.s    .CheckX
  230. .NoBounce
  231.     move.w    d0,BE_YCoord(a2)    ;d0 = Save the change.
  232.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the bob down.
  233.  
  234. .CheckX    move.w    BE_XCoord(a2),d0
  235.     add.w    BE_XSpeed(a2),d0
  236.     cmp.w    GS_Width(a0),d0
  237.     bcs.s    .NoXBounce
  238.     neg.w    BE_XSpeed(a2)
  239.     bra.s    .Animate
  240. .NoXBounce
  241.     move.w    d0,BE_XCoord(a2)
  242.  
  243. ;---------------------------------------------------------------------------;
  244.  
  245. .Animate
  246.     tst.w    BE_Locked(a2)
  247.     beq.s    .exit
  248.     move.w    d7,d6
  249.     and.w    #%00000011,d6
  250.     bne.s    .exit
  251.     move.w    BE_FChange(a2),d1
  252.     bgt.s    .Positive
  253.  
  254. .Negative
  255.     cmp.w    #1,BE_Set(a2)
  256.     bgt.s    .NBlue
  257.     beq.s    .NGreen
  258. .NRed    add.w    d1,BE_Frame(a2)
  259.     tst    BE_Frame(a2)
  260.     bge.s    .exit
  261.     move.w    #1,BE_FChange(a2)
  262.     clr.w    BE_Frame(a2)
  263.     rts
  264. .NGreen    add.w    d1,BE_Frame(a2)
  265.     cmp.w    #4,BE_Frame(a2)
  266.     bge.s    .done
  267.     move.w    #1,BE_FChange(a2)
  268.     move.w    #4,BE_Frame(a2)
  269.     rts
  270. .NBlue    add.w    d1,BE_Frame(a2)
  271.     cmp.w    #8,BE_Frame(a2)
  272.     bge.s    .done
  273.     move.w    #1,BE_FChange(a2)
  274.     move.w    #8,BE_Frame(a2)
  275. .exit    rts
  276.  
  277. .Positive
  278.     cmp.w    #1,BE_Set(a2)
  279.     bgt.s    .PBlue
  280.     beq.s    .PGreen
  281. .PRed    add.w    d1,BE_Frame(a2)
  282.     cmp.w    #3,BE_Frame(a2)
  283.     ble.s    .done
  284.     move.w    #-1,BE_FChange(a2)
  285.     move.w    #2,BE_Frame(a2)
  286.     rts
  287. .PGreen    add.w    d1,BE_Frame(a2)
  288.     cmp.w    #7,BE_Frame(a2)
  289.     ble.s    .done
  290.     move.w    #-1,BE_FChange(a2)
  291.     move.w    #6,BE_Frame(a2)
  292.     rts
  293. .PBlue    add.w    d1,BE_Frame(a2)
  294.     cmp.w    #11,BE_Frame(a2)
  295.     ble.s    .done
  296.     move.w    #-1,BE_FChange(a2)
  297.     move.w    #10,BE_Frame(a2)
  298. .done    rts
  299.  
  300. ;===========================================================================;
  301. ;                                  DATA
  302. ;===========================================================================;
  303.  
  304.     STRUCTURE    NBE,BE_SIZEOF    ;Definition for the mutated Entry-
  305.     WORD    BE_XSpeed    ;list in the Ball bob.
  306.     WORD    BE_YSpeed
  307.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  308.     WORD    BE_FChange
  309.     WORD    BE_Locked
  310.     LABEL    NBE_SIZEOF
  311.  
  312. JoyData:    dc.l  0
  313.  
  314. ;---------------------------------------------------------------------------;
  315.  
  316. RestoreTags:    dc.l  TAGS_RESTORE
  317. Restore:    dc.l  0
  318.         dc.l  RSA_Entries,MAX_IMAGES
  319.         dc.l  TAGEND
  320.  
  321. ;---------------------------------------------------------------------------;
  322.  
  323. ScreenTags:    dc.l  TAGS_SCREEN
  324. Screen:        dc.l  0
  325.         dc.l  GSA_Raster
  326. Raster:        dc.l  0
  327.         dc.l  GSA_Width,640
  328.         dc.l  GSA_Height,512
  329.         dc.l  GSA_Attrib,DBLBUFFER
  330.         dc.l  GSA_ScrMode,HIRES|LACED
  331.         dc.l    GSA_BitmapTags,0
  332.         dc.l    BMA_AmtColours
  333. GSColours:    dc.l    0
  334.         dc.l    TAGEND,0
  335.         dc.l  GSA_Palette
  336. GSPalette:    dc.l  0
  337.         dc.l  TAGEND
  338.  
  339. RastCList:    dc.w  ID_RASTCOLOURLIST,1
  340.         dc.l  0,0,0
  341.         dc.w  300,30    ;YCoord, Skip
  342.         dc.l  0    ;Colour
  343.         dc.l  .colours    ;Values
  344.  
  345. .colours    dc.l  $100000,$200000,$300000,$400000,$500000,$600000,$700000
  346.         dc.l  -1
  347.  
  348. ;---------------------------------------------------------------------------;
  349.  
  350. TAGS_Ball:    dc.l  TAGS_MBOB
  351. MBOB_Ball:    dc.l  0
  352.         dc.l  MBA_AmtEntries,MAX_IMAGES
  353.         dc.l  MBA_GfxCoords,BallFrames
  354.         dc.l  MBA_Width,16
  355.         dc.l  MBA_Height,16
  356.         dc.l  MBA_EntryList,Images
  357.         dc.l  MBA_Attrib,BBF_GENMASKS|BBF_CLRNOMASK|BBF_CLEAR|BBF_CLIP
  358.         dc.l  MBA_Source
  359. BallPic:    dc.l  0
  360.         dc.l  MBA_EntrySize,NBE_SIZEOF
  361.         dc.l  TAGEND
  362.  
  363. BallFrames:    dc.w  00,16*0    ;RED
  364.         dc.w  00,16*1
  365.         dc.w  00,16*2
  366.         dc.w  00,16*3
  367.         dc.w  16,16*0    ;GREEN
  368.         dc.w  16,16*1
  369.         dc.w  16,16*2
  370.         dc.w  16,16*3
  371.         dc.w  32,16*0    ;BLUE
  372.         dc.w  32,16*1
  373.         dc.w  32,16*2
  374.         dc.w  32,16*3
  375.         dc.l  -1
  376.  
  377. ;---------------------------------------------------------------------------;
  378.  
  379. PIC_BobTags:    dc.l  TAGS_PICTURE
  380. PIC_Bobs:    dc.l  0
  381.         dc.l    PCA_BitmapTags,0
  382.         dc.l    BMA_MemType,MEM_VIDEO
  383.         dc.l    TAGEND,0
  384.         dc.l  PCA_Source,.file
  385.         dc.l  TAGEND
  386.  
  387. .file        FILENAME "GMS:demos/data/PIC.HRPulse"
  388.  
  389. ;---------------------------------------------------------------------------;
  390.  
  391. TAGS_Interlaced    dc.l  TAGS_BOB
  392. BOB_Interlaced:    dc.l  0
  393.         dc.l  BBA_GfxCoords,LacedFrames
  394.         dc.l  BBA_Width,96
  395.         dc.l  BBA_Height,7
  396.         dc.l  BBA_Attrib,BBF_GENMASKS
  397.         dc.l  BBA_Source
  398. LacedPic:    dc.l  0
  399.         dc.l  TAGEND
  400.  
  401. LacedFrames:    dc.w  0,16*4    ;X/Y Graphic
  402.         dc.l  -1
  403.  
  404. ;---------------------------------------------------------------------------;
  405.  
  406.     SECTION    Images,BSS
  407.  
  408. Images    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  409.  
  410. ;===========================================================================;
  411.  
  412. ProgName:    dc.b  "Bouncing Bobs",0
  413. ProgAuthor:    dc.b  "Paul Manias",0
  414. ProgDate:    dc.b  "10 December 1997",0
  415. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1997.  Freely distributable.",0
  416. ProgShort:    dc.b  "Multiple bob demonstration.",0
  417.         even
  418.  
  419.